package com.wx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wx.pojo.IndexSource;
import com.wx.service.SourceService;
/**
 *首页查询搜索
 */
@Controller
@RequestMapping("/search")
public class SearchController {

	@Autowired
	private SourceService sourceService;
	/**
	 * 通过关键字搜索查询商品信息
	 * @param sourceName
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/searchByName",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object>searchSourceByName(@RequestParam(value="sourceName")String sourceName) throws Exception{
		Map<String, Object> modelMap=new HashMap<>();
		sourceName=new String(sourceName.getBytes("iso8859-1"),"UTF-8");
		System.out.println(sourceName);
		List<IndexSource> sourceList=sourceService.findSourceByName(sourceName);
		System.out.println(sourceList);
		if(!sourceList.isEmpty() || sourceList.size()>0) {
			modelMap.put("errno", 0);
			modelMap.put("sourceList", sourceList);
		}else {
			modelMap.put("errno", 1);
		}
		return modelMap;
	} 
	
}
